<?php
namespace  service\login;

use encryption\Token;
use encryption\Encryption;

class ApAction {
    /**
     * @desc 账号密码登录
     * @param $params
     * @return array
     * @author zhaozhiwei
     * @date 2021-02-04 13:06
     */
    public static function main($params){
        $user=\UserModel::getUserInfo($params['account']);
        if(empty($user)) return \Output2::fail(5001);
        //校验密码
        if($user['pwd'] !== Encryption::pwd_crype($params['password'])) return \Output2::fail(5002);
        if ($user['status'] == 0) return \Output2::fail(5003);

        //检测积分是否增加
        if (time() - (int)$user['last_time'] > 24 * 3600) {
            \UserModel::integralChange($user['uid']);
        }
        $arr=[
            'last_ip'=>(new \ip\Ip())->ip(),//獲取真實ip 需要一解決反向代理的方法
            'last_time'=>time(),//最后一次登陸時間
        ];
        \UserModel::updateUserInfo($arr,$user['uid']);
        //生成token
        $user['token']=Token::getToken(['user_id'=>$user['uid'],'mobile'=>$user['phone']]);
        return \Output2::success($user);
    }

}